package com.yanqu.road.server.logic.activity.condition.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.GetRechargeMallResult;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

/**
 * 现金礼包：新手珍兽福袋
 */
public class RechargeNewPlayerVehiclePackageActivityCondition extends BaseActivityCondition {

    public RechargeNewPlayerVehiclePackageActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RechargeNewPlayerVehiclePackage.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RechargeNewPlayerVehiclePackage.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        int args = (int) object;
        if (args > 0) {
            //加道具，设置购买状态
            if (getValue().intValue() == args) {
                getRMBMallActivityReward(args);
            }
        } else {
            long status = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.NewPlayerVehiclePackageStatus);
            if (status == 0 || args == -666) {//直接触发暗号
                if (getValue().compareTo(BigInteger.ZERO) == 0) {
                    GetRechargeMallResult result = player.getModule(ActivityModule.class).getShowRMBMallInfo(activityConditionInfo);
                    if (result.isDuringCd() && args != -666) {
                        return;
                    }
                    setRMBMallActivityInfo(result.getMallInfo());
                    player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.NewPlayerVehiclePackageStatus, 1);
                }
            }
        }
    }
}
